package com.bw.module_car.view


import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.GridLayoutManager
import com.bw.lib_base.view.BaseActivity
import com.bw.module_car.R
import com.bw.module_car.adpter.ProvincesAdapter
import com.bw.module_car.databinding.ActivityAddCarBinding
import com.bw.module_car.entity.ProvincesEntity
import com.bw.module_car.viewmodel.CarViewModel
import dagger.hilt.android.AndroidEntryPoint
/**
 * 智慧园区-02-添加车辆-v1.1-曲烨-20250509
 */
@AndroidEntryPoint
class AddCarActivity : BaseActivity<ActivityAddCarBinding>() {


    private val vm by lazy { ViewModelProvider(this)[CarViewModel::class.java] }
    private lateinit var provincesAdapter: ProvincesAdapter

    private val provincesList:List<ProvincesEntity> = arrayListOf()

    override fun initView() {
        super.initView()
        mDataBinding.addCarRv.layoutManager = GridLayoutManager(this,7)


        provincesAdapter = ProvincesAdapter()

        vm.getProvinces()
        vm.getProvincesSuccess.observe(this){

            provincesAdapter.data.addAll(it)
            mDataBinding.addCarRv.adapter = provincesAdapter
            provincesAdapter.notifyDataSetChanged()
        }


        mDataBinding.back.setOnClickListener {
            finish()
        }



        provincesAdapter.setOnItemClickListener { adapter, view, position ->
            mDataBinding.provinceName.setText(provincesAdapter.data[position].abbreviation)
        }


        mDataBinding.carAddAdd.setOnClickListener {
            startActivity(Intent(this,CarPayActivity::class.java))
        }



    }


    override fun getLayoutId(): Int {
        return R.layout.activity_add_car
    }

}